package com.learn.mvc.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class EmpHandler {

    Logger logger = LoggerFactory.getLogger(this.getClass());
    @RequestMapping(value = "/emp",method = RequestMethod.PUT)
    public String updateEmp(@RequestParam("message") String message) {
        logger.debug("现在执行的是 updateEmp() 方法 ");
        logger.debug(message);
        return "target";
    }

    @RequestMapping(value = "/emp", method = RequestMethod.DELETE)
    public String deleteEmp() {
        logger.debug("现在执行的是 deleteEmp() 方法 ");

        return "target";
    }

    // 实际地址：/emp/20
    // 映射地址：/emp/{empId}是吧变量部分用大括号标记出来，写入变量名
    @RequestMapping("/emp/{empId}")
    public String getEmpById(@PathVariable("empId") Integer empId) {
        logger.debug("empId = " + empId);
        return "target";
    }

    // 实际地址：/emp/20/tom/9999.9
    @RequestMapping("/emp/{empId}/{empName}/{empSalary}")
    public String queryEmpId(
            @PathVariable("empId") Integer empId,
            @PathVariable("empName") String empName,
            @PathVariable("empSalary") Double empSalary
    ) {

        logger.debug("empId = " + empId);
        logger.debug("empName = " + empName);
        logger.debug("empSalary = " + empSalary);
        return "target";
    }
}
